home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Modules / BackSpaceModules / Source / SpiroFrog / SpiroFrogViewPart.m < prev    next >
Text File  |  1994-05-04  |  2KB  |  103 lines

  1. #import "SpiroFrogViewPart.h"
  2. #import "Thinker.h"
  3. #import <appkit/NXImage.h>
  4. #import <appkit/Window.h>
  5. #import <appkit/Panel.h>                // for NXRunAlertPanel()
  6. #import <dpsclient/wraps.h>
  7. #import <libc.h>
  8. #import <math.h>
  9.  
  10. @implementation SpiroFrogView
  11.  
  12. - oneStep
  13. {
  14.   float mx, my;
  15.   float xi, yi;
  16.   p=n; n=(n+1)%(NUMLINES-1);
  17.   erasep=erase;
  18.   erase=(n-lper); if(erase<0) erase+=(NUMLINES-1);
  19.   if(n>(NUMLINES-1))n=0;
  20.  
  21.   PScurrentmouse(winNum, &mx, &my);
  22.   xi=((mx-midx)/urx)*10.0;
  23.   yi=((my-midy)/ury)*10.0;
  24.  
  25.   if((count++>500) && (((mx != oldx) && (my != oldy)) || (count>30000))){
  26.     count=0;
  27.     PSsetgray(0.0);
  28.     NXRectFill(&bounds);
  29.   }
  30.   oldx=mx; oldy=my;
  31.  
  32.   t1[n]=t1[p]+0.2*xi; if(t1[n]>(2*PI)) t1[n]-=(2*PI);
  33.   t2[n]=t2[p]+0.2*yi; if(t2[n]>(2*PI)) t2[n]-=(2*PI);
  34.   t3[n]=t3[p]+0.01;   if(t3[n]>(2*PI)) t3[n]-=(2*PI);
  35.  
  36.   x1[n]=(cos(t1[n])*s1) + (cos(t2[n])*s3) + midx;
  37.   yc1[n]=(sin(t1[n])*s2) + (sin(t2[n])*s4) + midy;
  38.   
  39.   PSsetrgbcolor(0.0,0.0,0.0);
  40.   PSmoveto(x1[erasep], yc1[erasep]);
  41.   PSlineto(x1[erase], yc1[erase]);
  42.   PSstroke();
  43.  
  44.  
  45.   if ([self shouldDrawColor])
  46.   PSsetrgbcolor((cos(t1[n])+1.0)/2.0,
  47.                 (cos(t2[n])+1.0)/2.0,
  48.                 (cos(t3[n])+1.0)/2.0);
  49.   else PSsetrgbcolor(1.0, 1.0, 1.0);
  50.   PSmoveto(x1[p], yc1[p]);
  51.   PSlineto(x1[n], yc1[n]);
  52.   PSstroke();
  53.  
  54.   return self;
  55. }
  56.  
  57. - initFrame:(NXRect *)frameRect
  58. {
  59.   [super initFrame:frameRect];
  60.   [self newSize];
  61.   winNum=[[self window] windowNum];
  62.   return self;
  63. }
  64.  
  65. - sizeTo:(NXCoord)width :(NXCoord)height
  66. {
  67.   [super sizeTo:width :height];
  68.   [self newSize];
  69.   return self;
  70. }
  71.  
  72. - newSize
  73. {
  74.   urx=bounds.size.width;
  75.   ury=bounds.size.height;
  76.   
  77.   midx=urx/2;
  78.   midy=ury/2;
  79.  
  80.   n = 0;
  81.   t = 0;
  82.   
  83.   // phases of the three points;
  84.   p1=0;
  85.   p2=(4*PI)/3;
  86.   p3=(2*PI)/3;
  87.   
  88.   // starting angle of each point;
  89.   t1[0]=0;
  90.   t2[0]=p2;
  91.   t3[0]=p3;
  92.  
  93.   // s1 and s2 should define an oval that takes up middle 75% of the screen
  94.   s1 = midx*0.5; s2 = midy*0.5;
  95.   s3 = midx*0.5; s4 = midy*0.5;
  96.  
  97.   // line per is the percentage back that erase steps
  98.   lper=NUMLINES-5;
  99.   return self;
  100. }
  101.  
  102. @end
  103.